<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的复制</title>
    <script>
        /*
        1.Object.assign(目标对象，被复制的对象)
        将被复制对象中的属性复制到目标对象里，并将目标对象返回
        2.使用展开运算符
        */

        const obj = {
            name: "孙悟空",
            age: 18
        }
        const obj2 = {
            address: "花果山",
            age: 48
        }

        //相同属性，后面的值覆盖前面的
        Object.assign(obj2, obj)
        console.log(obj2)   //{address: "花果山", age: 18, name: "孙悟空"}

        const obj3 = {
            address: "花果山",
            ...obj,
            age: 48
        }
        //相同属性，后面的值覆盖前面的
        console.log(obj3)   //{address: "花果山", name: "孙悟空", age: 48}
    </script>
</head>

<body>

</body>

</html>